package jcu.ict.profaid;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class FormSignUp extends Activity {
	private static SignDbAdapter SignupDb;

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.form_sign_up);

		final EditText edtName = (EditText) findViewById(R.id.edtName);
		final EditText edtEmail = (EditText) findViewById(R.id.edtEmail);
		final EditText edtCont = (EditText) findViewById(R.id.edtCont);

		SignupDb = new SignDbAdapter(getBaseContext());

		Button btnSignUp = (Button) findViewById(R.id.btnSignUp);
		btnSignUp.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				String name = edtName.getText().toString();
				String email = edtEmail.getText().toString();
				String contact = edtCont.getText().toString();

				if(name.equalsIgnoreCase("")|| email.equalsIgnoreCase("")||contact.equalsIgnoreCase("")){
					edtName.setError("Please put your name");
					edtEmail.setError("Please put your e-mail");
					edtCont.setError("Please put your number");
					if(name.trim().length() > 0) edtName.setError(null);
					if(email.trim().length() > 0) edtEmail.setError(null);
					if(contact.trim().length() > 0) edtCont.setError(null);
				}
				else{
					try {
						SignupDb.open();
						SignupDb.insertSignUp(name, email, contact);
						SignupDb.close();

						Toast.makeText(getBaseContext(), "Sign Up is succesfull!",
								Toast.LENGTH_LONG).show();

						Intent myIntent = new Intent(FormSignUp.this,
								FormSignIn.class);
						startActivity(myIntent);
						finish();
					} catch (Exception e) {
						Toast.makeText(getBaseContext(), "Please Sign Up Again...",
								Toast.LENGTH_LONG).show();
					}
				}
			}

		});
	}
}
